package com.bazaaroid.server.gae.api.resources.partner;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.bazaaroid.server.gae.core.dao.partner.PartnerDAO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO;
import com.bazaaroid.server.gae.core.dto.partner.PartnerDTO;
import com.bazaaroid.server.gae.core.dto.partner.AllEntitiesDTO.PartnersDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.partner.Partner;
import com.google.appengine.api.datastore.KeyFactory;

@Path("/partner/")
public class PartnerResource {

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/{id}")
	public PartnerDTO getById(@PathParam ("id") Long id) {
		PartnerDAO partnerDAO = GuiceFactory.getInjector().getInstance(PartnerDAO.class);
		Partner partner = partnerDAO.getById(KeyFactory.createKey(
				Partner.class.getSimpleName(), id));
		return new PartnerDTO(partner);
	}

	@GET
	@Produces( { "application/xml", "application/json" })
	@Path("/all/")
	public PartnersDTO getAllPartners() {
		PartnerDAO partnerDAO = GuiceFactory.getInjector()
			.getInstance(PartnerDAO.class);
		List<Partner> partners = partnerDAO.getAll();
		return new AllEntitiesDTO.PartnersDTO(partners);
	}

}
